#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "nanoDisk.h"


FILE *disk;
int time, last_sector;


void OpenDisk(char *name){
	disk = fopen(name,"r+");
	time = 0;
	last_sector = 0;
}

void SeekIt(int sector){
	fseek(disk, sector*SECTORSIZE, SEEK_SET);
	time += abs(last_sector-sector);
	last_sector = sector;
}

void ReadIt(Data *data){
	fread(&(data->buf), sizeof(char), sizeof(SECTORSIZE), disk);
}

void WriteIt(Data *data){
	fwrite((char *)data->buf, sizeof(char), SECTORSIZE, disk);
}

void CloseDisk(){
	fclose(disk);
}

void GetSeekTime(){
	printf("total time: %d\n",time);
}